package com.sx.zongzhi.presenter;

import com.sx.zongzhi.MyApplication;
import com.sx.zongzhi.bean.KeyTradesDetailBean;
import com.sx.zongzhi.modle.ApiManager;
import com.sx.zongzhi.net.BaseCallBack;
import com.sx.zongzhi.net.BaseResult;
import com.sx.zongzhi.view.IKeyAreaAddView;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by XZY on 2017/11/30.
 *重点行业添加/更新
 */
public class KeyTradesAddPest {

    private IKeyAreaAddView areaAddView;

    public KeyTradesAddPest(IKeyAreaAddView areaAddView) {
        this.areaAddView=areaAddView;
    }


    /**
     *
     * @param path 地址类型
     * @param id 重点行业id
     * @param detailBean
     */
    public void AddKeyTrades(String path,String id,String orgId,KeyTradesDetailBean detailBean,String url){
        Map<String,Object> map=new HashMap<>();
        map.put("sid", MyApplication.sid);
        map.put("keyIndustry.id", id);//重点行业id
        map.put("keyIndustry.organization.id", orgId);//网格
        map.put("keyIndustry.name",detailBean.getName());
        map.put("keyIndustry.industryType.id", detailBean.getType().getId());
        map.put("keyIndustry.quality.id", detailBean.getQuality()!=null ?
                detailBean.getQuality().getId():"");
        map.put("keyIndustry.licenseNumber", detailBean.getLicenseNumber());
        map.put("keyIndustry.nativePoliceStation", detailBean.getNativePoliceStation());
        map.put("keyIndustry.registeredCapital", detailBean.getRegisteredCapital());
        map.put("keyIndustry.telephone", detailBean.getTelephone());
        map.put("keyIndustry.faxTelephone", detailBean.getFax());
        map.put("keyIndustry.legalRepresentative",  detailBean.getLegalRepresentative());
        map.put("keyIndustry.employeesNumber",  detailBean.getEmployeesNumber());
        map.put("keyIndustry.legalPersonPhone",  detailBean.getLegalPersonPhone());
        map.put("keyIndustry.mobileNumber", detailBean.getMobileNumber());
        map.put("keyIndustry.address",  detailBean.getAddress());
        map.put("keyIndustry.attentionExtent.id",  detailBean.getAttentionExtent()!=null?
                detailBean.getAttentionExtent().getId():"");
        map.put("keyIndustry.hasDanger",  detailBean.isHasDanger());
        map.put("keyIndustry.dangerCase",  detailBean.getDangerCase());
        map.put("keyIndustry.dangerReformCase",  detailBean.getDangerReformCase());
        map.put("keyIndustry.remark",  detailBean.getRemark());
        map.put("file.path", url);
        new ApiManager().AddKeyTrades(path,map, new BaseCallBack<BaseResult<Boolean>>() {
            @Override
            public void onSuccess(BaseResult<Boolean> response) {
                areaAddView.addSuccess(response.getData());
            }
            @Override
            public void onFailures(String message) {
                areaAddView.showError(message);
            }
        });
    }

    /**
     * 判断是否有相同的名称
     * @param path 地址类别
     * @param orgId 网格id
     * @param name 名称
     * @param id (建议新增时不提交,更新时提交当前更改重点区域id)
     */
    public void AddKeyTrades(String path,String orgId,String name,String id){
        Map<String,Object> map=new HashMap<>();
        map.put("sid", MyApplication.sid);
        map.put("keyIndustry.organization.id", orgId);//网格
        map.put("keyIndustry.name",name);
        map.put("keyIndustry.id", id);//行业id
        new ApiManager().AddKeyTrades(path,map, new BaseCallBack<BaseResult<Boolean>>() {
            @Override
            public void onSuccess(BaseResult<Boolean> response) {
                areaAddView.nameSuccess(response.getData());
            }
            @Override
            public void onFailures(String message) {
                areaAddView.showError(message);
            }
        });
    }

}
